package edu.geo.containers.geom.impl;

import java.io.Serializable;

import com.vividsolutions.jts.geom.CoordinateSequence;

import edu.geo.containers.geom.Feature;

/**
 * 
 * @author alejandro.sanchez
 *
 */
public class Point extends com.vividsolutions.jts.geom.Point implements Feature, Serializable {
	
	public static final int DEFAULT_POINT_ID = -1;
	
	
	//private static final String GEOJSON_TEMPLATE = "{\\\"{type}\\\": \\\"{Point}\\\",\\\"{coordinates}\\\": [ {0}, {1} ]}";
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1056146673484594343L;
	
	int id = DEFAULT_POINT_ID;


	private String strId;

	protected Point(CoordinateSequence coordinates, com.vividsolutions.jts.geom.GeometryFactory factory) {
        super(coordinates, factory);
    }

	public int getId() {
		return id;
	}

	public String getAsWKT() {
		return this.toText();
	}

	public String getAsGML() {
		StringBuilder gmlPoint = new StringBuilder();
        gmlPoint.append("      <gml:Point>");
        gmlPoint.append("\n");
        gmlPoint.append("        <gml:pos dimension=\"2\">");
        gmlPoint.append( Double.toString( this.getX()) );
        gmlPoint.append( " " );
        gmlPoint.append( Double.toString( this.getY()) );
        gmlPoint.append("</gml:pos>");
        gmlPoint.append("\n");
        gmlPoint.append("      </gml:Point>");
        return gmlPoint.toString();
	}

	public String getAsGeoJson() {
		StringBuffer buffer = new StringBuffer();
		//"{\"{type}\": \"{Point}\",\"{coordinates}\": [ {0}, {1} ]}"
		buffer.append("{\"type\": \"Point\",\"coordinates\": [");
		buffer.append(Double.toString(this.getX()));
		buffer.append(",");
		buffer.append(Double.toString(this.getY()));
		buffer.append("]}");
		return buffer.toString();
	}

	@Override
	public void setId(int id) {
		this.id = id;		
	}

	@Override
	public boolean equals(Object obj) {
		Point oPoint = (Point)obj;
		return this.getX() == oPoint.getX()
				&& this.getY() == oPoint.getY()
                && this.id == ((Point)obj).getId() ;
	}

	@Override
	public String getStrId() {
		return strId;
	}

	@Override
	public String asSpaghettiRepresentation() {
		StringBuffer buffer = new StringBuffer();			
		buffer.append("[");
		buffer.append(getId());
		buffer.append("]");
		return buffer.toString();		
	}

	public void setStrId(String strId) {
		this.strId = strId;		
	}
	
	
}
